<?php
namespace soft\tagLib;
use think\template\TagLib;
//require "extend/lib/lessc/lessc.inc.php";

class load extends TagLib{
	//定义清缓存的引入标签，<load:css  src=""> ，<load:js  src="">
    protected $tags = array(
        'css' => array('attr' => 'src','close' =>0),
        'js' => array('attr' => 'src','close' =>0),
 	);
 	
 	public function tagCss ($attr,$content){
		$src = $this->getPath( $attr['src'] );
		return "<link  rel='stylesheet' href='$src'/>";
    }
	
    public function tagJs ($attr,$content){
       	$src = $this->getPath( $attr['src'] );
        return "<script src='$src'></script>";
    }
	
	//获取路径
	private function getPath($src){
		if (! function_exists('base_path')) {
		    function base_path($path = ''){
		        return env('root_path').($path ? ltrim($path, DIRECTORY_SEPARATOR) : 
		        ltrim($path, DIRECTORY_SEPARATOR));
		    }
		}
	    $oid_src = $src;
        if(!strstr($src, '__PUBLIC__') && !strstr($src, '__ROOT__')){
            $oid_src = str_replace("/modules","/", APP_PATH.'/'.config('template.view_path')).$src;
            if(INDEX_PATH == '/'){
                $src = './views/'.$src;
            }else{
                $src = '/views/'.$src;
            }
        }
        $path = str_replace("__PUBLIC__",'/public', $src);
        $ver = md5_file(  base_path().$path );
		return $oid_src.'?ver='.$ver;
	}
 
}
?>